package com.yzk.action;


import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;
import com.yzk.frame.utils.util.Page;
import com.yzk.frame.utils.util.PageRequest;
import com.yzk.user.model.SysUser;
import com.yzk.user.service.ISysUserSer;

@Namespace("/")
@Results( { @Result(name = "ok", location = "/ok.html") })
public class SysuserAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private SysUser entity;
	private ISysUserSer sysUserSerImp ;
	private Page<SysUser> page = new Page<SysUser>();

	public String saveuser() {
		System.out.println("run saveuser method");
		entity = new SysUser();
		entity.setLoginName("1");
		entity.setLoginPassword("2");
		entity.setNickName("3");
		entity.setEmail("abc@adfg.com");
		sysUserSerImp.save(entity);
		System.out.println("over");
		return "ok";
	}
	
	public String getAll() {
		List<SysUser> list =sysUserSerImp.listUser();
		list.size();
		for(SysUser u : list) {
			System.out.print(u.getUid()+"--"+u.getLoginName()+"--"+u.getLoginPassword()+"\n");
		}
		return "ok";
	}
	
	public String list() {
		if (!page.isOrderBySetted()) {
			page.setOrderBy("id");
			page.setOrderDir(PageRequest.Sort.ASC);
		}
		return null;
	}
	
	public String deluser() {
		sysUserSerImp.delUser(1);
		return "ok";
	}
	
	
	public String findUser() {
		System.out.println("findUser method run:");
		SysUser user = sysUserSerImp.findById(5);
		System.out.println("---"+user.getLoginName());
		return "ok";
	}
	
	
	public SysUser getEntity() {
		return entity;
	}

	public void setEntity(SysUser entity) {
		this.entity = entity;
	}

	public ISysUserSer getSysUserSerImp() {
		return sysUserSerImp;
	}

	@Resource
	public void setSysUserSerImp(ISysUserSer sysUserSerImp) {
		this.sysUserSerImp = sysUserSerImp;
	}




	
	
}
